package com.baoyouqun.service;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baoyouqun.API.IM.entity.FriendStatus;
import com.baoyouqun.domain.CreateCmd.BackUserCreateCmd;
import com.baoyouqun.domain.CreateCmd.UserCreateCmd;
import com.baoyouqun.domain.CreateCmd.UserResourceCreateCmd;
import com.baoyouqun.domain.Query.UserDetailQuery;
import com.baoyouqun.domain.Query.UserQuery;
import com.baoyouqun.domain.UpdateCmd.BackUserUpdateCmd;
import com.baoyouqun.domain.UpdateCmd.UserUpdateCmd;
import com.baoyouqun.domain.VO.*;
import com.baoyouqun.domain.cmd.BatchDeleteUserCmd;
import com.baoyouqun.domain.cmd.ExportUserCmd;
import com.baoyouqun.domain.cmd.ResetPasswordCmd;
import com.baoyouqun.domain.cmd.UpdatePasswordCmd;
import com.baoyouqun.entity.User;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;


public interface UserService extends IService<User> {

    /**
     * 新增并返回实体
     */
    SingleResponse<UserVO> create(UserCreateCmd cmd);

    SingleResponse<UserVO> updateBackUser(BackUserUpdateCmd cmd);

    SingleResponse<String> register(UserCreateCmd cmd);


    Response update(UserUpdateCmd cmd);

    Response disEnable(UserUpdateCmd cmd);

    // 正确的更新session_key方法
    boolean updateSessionKey(String openid, String sessionKey);

    Response setUserInfo(UserUpdateCmd userInfo, List<UserResourceCreateCmd> resourceList);

    /**
     * 根据ID查询VO
     */
    UserVO selectById(String id);

    UserVO userDetail(String id);


    /**
     * 分页查询VO
     */
    IPage<UserVO> pageVo(UserQuery query);

    User selectByCellphone(String phones);

    List<Map<String, Object>> countByAreaCodes();

    SingleResponse<List<RoleVO>> getUserRoles(String userId);

    Response setUserExtraPhones(String userId, List<String> extraPhones);

    User selectByWxOpenid(String openid);

    UserHomeVO userHome(String userId);

    boolean existsByWxOpenid(String wxOpenid);

    boolean existsByCellphone(String cellphone);

    // 新增以下方法
    Response batchDelete(BatchDeleteUserCmd cmd);

    Response resetPassword(ResetPasswordCmd cmd);

    void exportUser(ExportUserCmd cmd, HttpServletResponse response) throws IOException;

    SingleResponse<UserDetailVO> getUserDetail(UserDetailQuery query);

    SingleResponse<ImportUserVO> importUser(MultipartFile file) throws IOException;

    Response updatePassword(UpdatePasswordCmd cmd);

    IPage<UserDetailVO> backUserPage(UserQuery query);

    /**
     * 根据姓名、手机号、地区代码筛选用户ID列表（排除禁用/注销用户）
     */
    List<String> getUserIdListByConditions(String name, String cellphone, String cityCode);

    /**
     * 根据发布人名称模糊查询用户ID列表
     */
    List<String> listUserIdsByName(String name);

    List<String> listUserIdsByCellphone(String phoneNumber);

    List<UserVO> listByNameOrPhone(String keyword);

    SingleResponse<UserVO> createBackUser(BackUserCreateCmd cmd);

    boolean bindImId(String userId, String imId);

    /**
     * 分页查询公开豹友列表
     *
     * @param loginUserId 当前登录用户ID（排除自己）
     * @param current     当前页
     * @param size        每页条数
     * @param isOnline    是否筛选在线
     * @param isVip       是否筛选VIP
     * @param sameRegion  是否筛选老乡
     * @return 分页VO列表
     */
    IPage<PublicFriendVO> pagePublicFriends(String loginUserId, Long current, Long size,
                                            Boolean isOnline, Boolean isVip, Boolean sameRegion, String cityCode);

    /**
     * 搜索公开豹友
     *
     * @param loginUserId 当前登录用户ID（排除自己）
     * @param keyword     搜索关键词（昵称/手机号）
     * @param current     当前页
     * @param size        每页条数
     * @return 分页VO列表
     */
    IPage<PublicFriendVO> searchPublicFriends(String loginUserId, String keyword, Long current, Long size);

    List<FriendStatus> getFriendStatuses(String currentUserId, List<String> friendUserIds);

    List<User> getUsersForScoreCalculation(int i);

    List<String> selectRecentLoginUserIds(int recentHalf);

    List<String> selectUncalculatedUserIds(int limit);

    List<String> selectOtherActiveUserIds(int otherHalf, List<String> recentLoginUsers);

    void updateLastRecommendTime(String targetUserId, LocalDateTime now);

    Response cancelAccount(String userId);
}